package com.example.madman.yuejian.Fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.madman.yuejian.Adapter.ClubListAdapter;
import com.example.madman.yuejian.Bean.ClubBean;
import com.example.madman.yuejian.Listener.RetrofitListener;
import com.example.madman.yuejian.Model.ClubModel;
import com.example.madman.yuejian.R;

import java.util.ArrayList;
import java.util.List;


public class ClubListFragment extends Fragment {
    private RecyclerView recyclerView;
    private ClubListAdapter clubListAdapter;
    private List<ClubBean> list;
    private RecyclerView.LayoutManager layoutManager;
    private Context context;
    private RetrofitListener<List<ClubBean>> listener;
    private ClubModel model;







    public ClubListFragment() {
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_item_clublist, container, false);
        context=getActivity();
        recyclerView=(RecyclerView)view.findViewById(R.id.list_club);
        list=new ArrayList<ClubBean>();


        initdata();

        init();
        conhttp();

        return view;
    }


      private void initdata(){
     listener = new RetrofitListener<List<ClubBean>>() {
         @Override
         public void onSuccess(List<ClubBean> clubBeen) {
             list=clubBeen;
             clubListAdapter.setList(list);
         }
         @Override
         public void onFail(String msg) {
             Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
         }
     };
 }
       private void init(){
           layoutManager=new LinearLayoutManager(context);
           recyclerView.setLayoutManager(layoutManager);
           clubListAdapter = new ClubListAdapter(context);
           clubListAdapter.setList(list);
           recyclerView.setAdapter(clubListAdapter);
}
       private void conhttp(){
           model = new ClubModel("gson");
           model.getClubList(listener);
    }


}
